// @/store/firstStore.js
import { defineStore } from "pinia";
import { ElMessage } from "element-plus";
import { h } from "vue";
const fs = require("fs");
const path = require("path");
const Store = require("electron-store");
const { ipcRenderer } = require("electron");
const store = new Store();

const exec = require("child_process").exec;

// 定义并导出容器，第一个参数是容器id，必须唯一，用来将所有的容器
// 挂载到根容器上
export const useShotStore = defineStore("shotStore", {
  // 定义state，用来存储状态的
  state: () => {
    return {
      fileList: <any>[],
      formConfig: store.get("FormConfig.默认"),
      page: {
        asideIndex: "1",
        tabIndex: "1",
      },
      currConfigName: "默认", // 当前配置的名字
      config: {
        formConfigJson: store.get("FormConfig"),
        formConfigList: <any>[],
        configLable: <any>[],
        savePath: store.get("savePath"),
        sysSound: store.get("sysSound"),
        micSound: store.get("micSound"),
      },
      isLoading: false,
    };
  },
  // 定义getters，类似于computed，具有缓存g功能
  getters: {},
  // 定义actions，类似于methods，用来修改state，做一些业务逻辑
  actions: {
    setDoneStatus(filePath: string) { },
    setSavePath() {
      store.set("savePath", this.config.savePath);
      store.set("sysSound", this.config.sysSound);
      store.set("micSound", this.config.micSound);
    },
    genFormConfig() {
      this.config.formConfigList = Object.keys(this.config.formConfigJson).map(
        (item) => ({
          tagName: item,
          content: this.config.formConfigJson[item],
        })
      );
      this.config.configLable = Object.keys(this.config.formConfigJson).map(
        (item) => ({
          value: item,
          label: item,
        })
      );
    },
    showItemInFolder(filePath: string) {
      ipcRenderer.send("showItemInFolder", filePath);
    },
  },
});
